package org.qjzn.test.demos.web.domain.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.List;
import java.util.stream.Collectors;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class AuthorizationProductResponse {

    private String licFilePath;//文件路径
    private String applicat;//申请人
    private String formID;//流程表单实例id
    private String purpose; // 授权目的
    private String product; // 授权产品
    private String orgName; // 客户单位名称
    private String licType; // 授权类型
    private int licDays; // 授权天数
    private List<AuthorizationDetail> authorizationDetails; // 授权明细表
    private String licSelectMode; // 授权项选择模式
    private List<String> licModules; // 授权模块
    private List<String> licCasingFeats; // 通用功能模块
    private List<String> licTurboFeats; // 透平功能模块
    private List<String> licInspectFeats; // 测量功能模块
    private List<String> licPcdFeats; // PCD功能模块
    private List<String> licFitFeats; // 自适应功能模块
    private List<String> licOtherFeats; // 其他功能模块
    private String comment; // 备注


    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("{\n");
        sb.append("\"licFilePath\": \"").append(licFilePath).append("\",\n");
        sb.append("\"purpose\": \"").append(purpose).append("\",\n");
        sb.append("\"product\": \"").append(product).append("\",\n");
        sb.append("\"orgName\": \"").append(orgName).append("\",\n");
        sb.append("\"licType\": \"").append(licType).append("\",\n");
        sb.append("\"licDays\": ").append(licDays).append(",\n");
        sb.append("\"licSelectMode\": \"").append(licSelectMode).append("\",\n");
        sb.append("\"licModules\": ").append(serializeList(licModules)).append(",\n");
        sb.append("\"licCasingFeats\": ").append(serializeList(licCasingFeats)).append(",\n");
        sb.append("\"licTurboFeats\": ").append(serializeList(licTurboFeats)).append(",\n");
        sb.append("\"licInspectFeats\": ").append(serializeList(licInspectFeats)).append(",\n");
        sb.append("\"licPcdFeats\": ").append(serializeList(licPcdFeats)).append(",\n");
        sb.append("\"licFitFeats\": ").append(serializeList(licFitFeats)).append(",\n");
        sb.append("\"licOtherFeats\": ").append(serializeList(licOtherFeats)).append(",\n");
        sb.append("\"comment\": \"").append(comment).append("\",\n");
        sb.append("\"authorizationDetails\": ").append(serializeAuthorizationDetails(authorizationDetails)).append("\n");
        sb.append("}");
        return sb.toString();
    }

    private String serializeList(List<String> list) {
        if (list == null || list.isEmpty()) {
            return "[]";
        }
        return list.stream()
                .map(item -> "\"" + item + "\"")
                .collect(Collectors.joining(", ", "[", "]"));
    }

    private String serializeAuthorizationDetails(List<AuthorizationDetail> details) {
        if (details == null || details.isEmpty()) {
            return "[]";
        }
        return details.stream()
                .map(detail -> {
                    return "{\n" +
                            "\"custName\": \"" + detail.getCustName() + "\",\n" +
                            "\"needDongle\": " + detail.getNeedDongle() + ",\n" +
                            "\"computerId\": \"" + detail.getComputerId() + "\",\n" +
                            "\"connMachine\": " + detail.getConnMachine() + ",\n" +
                            "\"machineId\": \"" + detail.getMachineId() + "\",\n" +
                            "\"cnc\": \"" + detail.getCnc() + "\"\n" +
                            "}";
                })
                .collect(Collectors.joining(", ", "[\n", "\n]"));
    }
}
